﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CustomizationMaintEntry
{
    public partial class frmVersionSelect : Form
    {
        Boolean IsAutoSave = false;
        public frmVersionSelect(Boolean AutoSave, String strDataBase)
        {
            InitializeComponent();
            IsAutoSave = AutoSave;
            if (strDataBase.ToUpper() == "EPICOR10")
            { this.raEPICOR10.Checked = true; }
            else if (strDataBase.ToUpper() == "EPICORTEST")
            { this.raEPICORTest.Checked = true; }
            else if (strDataBase.ToUpper() == "EPICOR10TEST")
            { this.raE101600TEST.Checked = true; }
            else
            { txtOtherDb.Text = strDataBase; }
            if (IsAutoSave == true)
            {
                if (this.raE101600TEST.Checked == true)
                { this.cmbIP.Text = "192.168.100.42"; }
                if (SetConnection() == false)
                    return;
                (new frmCustomizationMaintEntryStandard(IsAutoSave)).ShowDialog();
            }
        }

        private void btnOpen1_Click(object sender, EventArgs e)
        {
            if (SetConnection() == false)
                return;
            (new frmCustomizationMaintEntry()).ShowDialog();
        }

        private void btnOpen2_Click(object sender, EventArgs e)
        {
            if (SetConnection() == false)
                return;
            (new frmCustomizationMaintEntry1023()).ShowDialog();
        }

        private void btnOpen3_Click(object sender, EventArgs e)
        {
            if (SetConnection() == false)
                return;
            (new frmCustomizationMaintEntryStandard(false)).ShowDialog();
        }

        private Boolean SetConnection()
        {
            Boolean IsOk = false;
            try
            {
                String strDataBase = "";
                if (raEPICOR10.Checked == true)
                { strDataBase = raEPICOR10.Text; }
                if (raE101600TEST.Checked == true)
                { strDataBase = raE101600TEST.Text; }
                if (raEPICORTest.Checked == true)
                { strDataBase = raEPICORTest.Text; }
                if (txtOtherDb.Text.Trim() != "")
                { strDataBase = txtOtherDb.Text.Trim(); }
                DbHelperSQL.strPubConnectionEpicor = String.Format("Data Source={0};Initial Catalog={1};persist security info=False;User ID={2};Password={3}", cmbIP.Text, strDataBase, txtUser.Text.Trim(), txtPassword.Text.Trim());
                IsOk = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return IsOk;
        }


    }
}
